<?php

use plugin\property\app\controller\AuthController;
use plugin\property\app\controller\PropertyPermissionController;
use plugin\property\app\controller\PropertyRoleController;
use plugin\property\app\controller\PropertyUserController;
use plugin\property\app\controller\HomeController;
use plugin\property\app\controller\IndexController;
use plugin\property\app\controller\PropertyMenuController;
use Webman\Route;

Route::get('/property', fn() => \plugin\property\app\Property::view('enterprise-api'));


Route::group('/' . config('plugin.property.property.route.prefix'), function () {

    Route::get('/login', [AuthController::class, 'loginPage']);
    Route::post('/login', [AuthController::class, 'login']);
    Route::get('/logout', [AuthController::class, 'logout']);
    Route::get('/captcha', [AuthController::class, 'reloadCaptcha']);
    Route::get('/current-user', [AuthController::class, 'currentUser']);

    Route::get('/menus', [IndexController::class, 'menus']);
    Route::get('/_settings', [IndexController::class, 'settings']);
    Route::post('/_settings', [IndexController::class, 'saveSettings']);
    Route::get('/no-content', [IndexController::class, 'noContentResponse']);
    Route::get('/_download_export', [IndexController::class, 'downloadExport']);
    Route::get('/_iconify_search', [IndexController::class, 'iconifySearch']);
    Route::get('/page_schema', [IndexController::class, 'pageSchema']);

    Route::any('/upload_file', [IndexController::class, 'uploadFile']);
    Route::any('/upload_chunk_start', [IndexController::class, 'chunkUploadStart']);
    Route::any('/upload_chunk', [IndexController::class, 'chunkUpload']);
    Route::any('/upload_chunk_finish', [IndexController::class, 'chunkUploadFinish']);
    Route::any('/upload_rich', [IndexController::class, 'uploadRich']);
    Route::any('/upload_image', [IndexController::class, 'uploadImage']);
    Route::get('/user_setting', [AuthController::class, 'userSetting']);
    Route::put('/user_setting', [AuthController::class, 'saveUserSetting']);

    Route::resource('/dashboard', HomeController::class);

    Route::group('/system', function () {
        Route::get('/', [PropertyUserController::class, 'index']);

        Route::resource('/property_users', PropertyUserController::class);

        Route::post('/property_menus/save_order', [PropertyMenuController::class, 'saveOrder']);
        Route::resource('/property_menus', PropertyMenuController::class);
        Route::resource('/property_roles', PropertyRoleController::class);
        Route::resource('/property_permissions', PropertyPermissionController::class);

        Route::post('/property_role_save_permissions', [PropertyRoleController::class, 'savePermissions']);
        Route::post('/_property_permissions_auto_generate', [PropertyPermissionController::class, 'autoGenerate']);

    });
});

